<?php
namespace Modules\Admin\Http\Controllers;
use Illuminate\Http\Request;
use Modules\Admin\Http\Requests\CommonDeleteRequest;
use Modules\Admin\Http\Requests\CommonDeleteAllRequest;
use Modules\Admin\Models\OperationLog as OperationLogModel;
use Modules\Admin\Http\Controllers\CommonController;
class OperationLogController extends CommonController
{
	/**
	 * @name  列表
	 */
    public function index()
    { 
		$status_lists = (new OperationLogModel())->status_lists();
        return view('admin::operation_log.index',compact('status_lists'));
    }
	/**
	 * @name  列表数据
	 */
	 
    public function data(Request $request)
    {
	    $model = OperationLogModel::query();
		$params = $request->all();
		$model = query_condition($model,$params,'url');
        /*$res = $model->whereHas('admin_one',function($admin_one){
			if(!empty($params['username'])){
				$admin_one->where('username','like','%' . $params['username'] . '%');
			}
			$admin_one->select('id','username');
		})*/ 
		$res = $model->whereHas('admin_one',function($query)use ($params){
			if(!empty($params['username'])){
				$query->where('username', 'like', '%' . $params['username'] . '%');
			}
		})->with(['admin_one'=>function($query){
			$query->select('id','username');  
		}])
				->orderBy('id','desc')  
				->paginate($params['limit'])
				->toArray(); 
				
		$res['data'] = (new OperationLogModel())->data_list($res['data']);	
        return response()->json(['code' => 0, 'msg'   => config('admin.limit_msg'),'count' => $res['total'],'data'  => $res['data'],'rel'=>1]);
    }
	/**
	 * @name  删除数据处理
	 */
    public function destroy(CommonDeleteRequest $request)
    {
		return (new OperationLogModel())->common_destroy($request->get('id'),route('admin.operation_log.index'));  
    }
	/**
	 * @name  批量删除数据处理
	 */
    public function destroy_all(CommonDeleteAllRequest $request)
    {
		return (new OperationLogModel())->common_destroy($request->get('ids'),route('admin.operation_log.index'));  
    }
	
	
	
	
	
}
